package com.webdemo02.action;

import java.sql.Connection;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.webdemo02.actionform.UserForm;
import com.webdemo02.util.DBHandler;

public class DeleteUser extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		UserForm user = (UserForm)form;
		int id = user.getId();
		String sql = "delete from xml01_user where id=?";
		Connection conn = DBHandler.newInstance().getConnection();
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1, id);
		pstmt.executeUpdate();
		ActionForward actionForward = new ActionForward("/QueryUser.do");
		actionForward.setRedirect(true);
		return actionForward;
	}

}
